package com.sevennotes.classtable.config

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
import java.util.Date

object Settings {
  var currentTableNameId: Int = 0
  var themeColor by mutableStateOf(Color(0xFF699B7B))
  var windowWidth: Int = 0
  var windowHeight: Int = 0
  var heightPercent by mutableStateOf(0f)
  var widthPercent by mutableStateOf(0f)
  var beginHour: Int by mutableStateOf(8)
  var endHour: Int by mutableStateOf(20)
  var webDavUrl: String by mutableStateOf("https://dav.jianguoyun.com/dav/")
  var dirName: String by mutableStateOf("classTable")
  var webDavUsername: String by mutableStateOf("")
  var webDavPassword: String by mutableStateOf("")
  //是否开启自动保存
  var autoSaveEnable: Boolean by mutableStateOf(false)
  var lastAutoSaveDate: Long = 0L
  //最大保存文件数
  var maxAutoSaveFileNumber: Int by mutableStateOf(7)
  //自动保存间隔天数
  var autoSaveIntervalDays: Int by mutableStateOf(1)
  //移动数据网络的情况下是否允许自动保存
  var shouldAutoSaveInMobileNetwork by mutableStateOf(false)

  val autoSaveDir
    get() = "${dirName}/auto"
  const val autoSaveFileName = "auto_save_"

  //最小时间单位的最小高度 , dp
  val minTimeHeight: Float
    get() {
      return (windowHeight - 100).toFloat() / (13 * (60 / MIN_TIME_MINUTE))
    }

  //一天的最小宽度
  val minDayWidth: Float
    get() {
      return (windowWidth - 27).toFloat() / 7
    }

  val hours: List<Int>
    get() {
      return List(endHour - beginHour) { it + beginHour }
    }
  val minutes: List<Int>
    get() {
      return List(60 / MIN_TIME_MINUTE) { it * MIN_TIME_MINUTE }
    }
  val durations: List<Int>
    get() {
      return List(105 / MIN_TIME_MINUTE) { it * MIN_TIME_MINUTE + 20 }
    }

  fun getClassChoiceList(): List<List<String>> {
    return listOf(
      Config.weekdays,
      hours.map { "$it 点" },
      minutes.map { "$it 分" },
      durations.map { "$it 分钟" }
    )
  }
}